﻿using News.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UboxUI;

namespace News
{
    public partial class Form1 :  FrmFather
    {
        public Form1()
        {
            InitializeComponent();
        }

        string conn = Settings.Default.strConn;

        private void Form1_Load(object sender, EventArgs e)
        {
            DataGridViewFill();
        }

        private void DataGridViewFill()
        {
            using (clsltosnewsDataContext db = new clsltosnewsDataContext(conn))
            {
                int managerid = 0;
                int newsid = 0;
                int.TryParse(this.txtManagerID.Text, out managerid);
                int.TryParse(this.txtNewsID.Text, out newsid);
                var q = from m in db.news
                        where
                        (chkNewsID.Checked ? newsid == m.news_id : true) &&
                        (chkManagerID.Checked ? managerid == m.manager_id : true) &&
                        (chkDate.Checked ? m.news_date >= this.dtpPulishDate1.Value && m.news_date <= this.dtpPulishDate2.Value : true)
                        select new
                        {
                            編號 = m.news_id,
                            公告標題 = m.news_title,
                            公告內容 = m.news_content,
                            公告管理員 =m.manager_id,
                            公告日期 = m.news_date,
                         

                        };
                this.dataGridView1.DataSource = q.ToList();
                this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            DataGridViewFill();    
        }

        

    }
}
